<template>
    <div class="app-container">
        <el-row>
            <el-col>
                <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                    label-width="72px">
                    <el-form-item label="证书类别" prop="contacts">
                        <el-select v-model="queryParams.type" placeholder="请选择证书类别">
                            <el-option v-for="dict in dict.type.certificate_type" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="证书级别" prop="contacts">
                        <el-select v-model="queryParams.level" placeholder="请选择证书级别">
                            <el-option v-for="dict in dict.type.certificate_level" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="证书名称" prop="contacts">
                        <el-input width="150px" v-model="queryParams.name" placeholder="请输入证书名称" clearable
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="状态" prop="contacts">
                        <el-select v-model="queryParams.status" placeholder="请选择状态">
                            <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-row :gutter="10" class="mb8">

                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>
              <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
                <el-table :cell-style="{ padding: '0px' }" height="450" border v-loading="loading"
                    :data="managementList" @selection-change="handleSelectionChange" highlight-current-row
                    :row-style="changeColor">

                    <el-table-column type="selection" width="55" align="center" />
                    <el-table-column label="序号" type="index" :index="indexMethod" />
                    <el-table-column label="获证时间" align="center" prop="entryTime" width="100"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="证书类别" align="center" prop="type" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.certificate_type" :value="scope.row.type" />
                        </template>
                    </el-table-column>
                    <el-table-column label="证书级别" align="center" prop="level" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.certificate_level" :value="scope.row.level" />
                        </template>
                    </el-table-column>
                    <el-table-column label="证书名称" align="center" prop="name" :show-overflow-tooltip="true" />
                    <el-table-column label="证书编号" align="center" prop="certificateNo" :show-overflow-tooltip="true" />
                    <el-table-column label="发证机构" align="center" prop="certificateInstitution"
                        :show-overflow-tooltip="true" />
                    <el-table-column label="服务机构" align="center" prop="serviceInstitu" :show-overflow-tooltip="true" />
                    <el-table-column label="有效时间" align="center" prop="effectiveTime" width="100"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.effectiveTime }}个月
                        </template>
                    </el-table-column>
                    <el-table-column label="证书到期日" align="center" prop="issuanceTime" width="100"
                        :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.issuanceTime, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="预警时间" align="center" prop="abutmentTime" width="100"
                        :class-name="getWarningClass" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span :style="{ color: getWarningColor(scope.row.abutmentTime) }">{{
                    parseTime(scope.row.abutmentTime,
                        '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="附件" align="center" prop="list" width="110">
                        <!--            <template slot-scope="scope">-->
                        <!--              <el-button v-if="scope.row.fileUrl !== null" @click.stop="handlePictureCardPreview(scope.row.fileUrl)"-->
                        <!--                size="small" type="text">附件</el-button>-->
                        <!--              <el-button v-else size="small" type="text">无附件</el-button>-->
                        <!--            </template>-->
                        <template slot-scope="scope">
                            <img v-if="scope.row.fileUrl" :src="scope.row.fileUrl" class="thumbnail-image" alt="附件图片" />
                        </template>
                    </el-table-column>
                    <el-table-column label="网址名称" align="center" prop="selectUrl" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <el-button @click="handleClick(scope.row.urlName)" type="text">
                                <dict-tag :options="dict.type.honor_urlname" :value="scope.row.urlName" />
                            </el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="状态" align="center" prop="status">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.honer_status" :value="scope.row.status" />
                        </template>
                    </el-table-column>
                    <el-table-column label="创建人" align="center" prop="createId" :show-overflow-tooltip="true"
                        width="100" />
                    <el-table-column label="创建时间" align="center" prop="creationTime" :width="100">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
              </div>
                <!-- 内部文本-->
            </el-col>
        </el-row>

        <!-- 添加或修改荣誉资质信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="730px" append-to-body :rules="rules">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
                <div v-if="addSign === 1">
                    <el-descriptions title="">
                        <el-descriptions-item label="序号">
                            <el-tag size="medium">{{ form.index }}</el-tag>
                        </el-descriptions-item>
                    </el-descriptions>
                </div>
                <el-form-item label="发证时间" prop="entryTime" label-width="110px">
                    <el-date-picker clearable v-model="form.entryTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择发证时间" style="width: 202.5px" class="custom-date-picker">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="预警时间" prop="abutmentTime" label-width="110px">
                    <el-date-picker clearable v-model="form.abutmentTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择预警时间" style="width: 202.5px"></el-date-picker>
                </el-form-item>
                <el-form-item label="证书名称" prop="name" label-width="110px">
                    <el-input v-model="form.name" placeholder="请输入证书名称" style="width: 202.5px" maxlength="20"
                        show-word-limit />
                </el-form-item>
                <el-form-item label="证书编号" prop="certificateNo" label-width="110px">
                    <el-input v-model="form.certificateNo" placeholder="请输入证书编号" style="width: 202.5px"
                        show-word-limit />
                </el-form-item>
                <el-form-item label="证书类别" prop="type" label-width="110px">
                    <el-select v-model="form.type" placeholder="请选择证书类别" style="width: 202.5px">
                        <el-option v-for="dict in dict.type.certificate_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="证书级别" prop="level" label-width="110px">
                    <el-select v-model="form.level" placeholder="请选择证书级别" style="width: 202.5px">
                        <el-option v-for="dict in dict.type.certificate_level" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="服务机构" prop="serviceInstitu" label-width="110px">
                    <el-input v-model="form.serviceInstitu" placeholder="请输入服务机构" style="width: 202.5px" maxlength="20"
                        show-word-limit />
                </el-form-item>
                <el-form-item label="发证机构" prop="certificateInstitution" label-width="110px">
                    <el-input v-model="form.certificateInstitution" placeholder="请输入发证机构" style="width: 202.5px" />
                </el-form-item>
                <el-form-item label="证书到期日" prop="issuanceTime" label-width="110px">
                    <el-date-picker clearable v-model="form.issuanceTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择证书到期日" style="width: 202.5px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="有效时间" prop="effectiveTime" label-width="110px">
                    <el-input v-model="form.effectiveTime" placeholder="请输入有效时间" style="width: 202.5px" type="number"
                        pattern="[0-9]*" :min="0" disabled="true" />
                    <span style="margin-left: 5px;">月</span>
                </el-form-item>
                <!--        <el-form-item label="查询网址" prop="selectUrl" label-width="110px">-->
                <!--          <el-input v-model="form.selectUrl" placeholder="请输入查询网址" style="width: 202.5px" maxlength="100" show-word-limit/>-->
                <!--        </el-form-item>-->
                <el-form-item label="网址名称" prop="urlName" label-width="110px">
                    <el-select v-model="form.urlName" placeholder="请选择状态" style="width: 202.5px">
                        <el-option v-for="dict in dict.type.honor_urlname" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="状态" prop="status" label-width="110px">
                    <el-select v-model="form.status" placeholder="请选择状态" style="width: 202.5px">
                        <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间" prop="creationTime" label-width="110px">
                    <el-date-picker clearable v-model="form.creationTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择时间" style="width: 202.5px" disabled="true">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="创建人" prop="createId" label-width="110px">
                    <el-input v-model="form.createId" placeholder="请输入创建人" disabled="true" style="width: 202.5px" />
                </el-form-item>
                <el-form-item label="附件" prop="uploadFile" label-width="110px">
                    <file-view v-if="showUpload" :type="typeSelectHonor" :businessId="form.uploadFile"
                        :businessCode="uploadCode"></file-view>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">关 闭</el-button>
            </div>
        </el-dialog>

        <!--    履历对话框-->
        <el-dialog title="履历列表" :visible.sync="resumeOpen" width="1200px" @close="resetReusumeClose()">
            <el-row>
                <!--            <el-col :span="5">-->
                <!--              <MainType :typeCode="typeCodeResume" @getNode="getNodeResume"></MainType>-->
                <!--            </el-col>-->
                <el-col :span="24">
                    <el-row :gutter="10" class="mb8">
                        <el-col :span="1.5">
                            <el-button type="primary" plain icon="el-icon-plus" size="mini"
                                @click="handleAddResume">新增</el-button>
                        </el-col>
                    </el-row>
                    <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" border
                        v-loading="loading" :data="resumeList" @selection-change="handleSelectionChange">
                        <el-table-column label="序号" type="index" :index="indexMethod" />
                        <el-table-column label="关联方式" align="center" prop="concat" :show-overflow-tooltip="true" />
                        <el-table-column label="创建时间" align="center" prop="honorTime" width="120"
                            :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.honorTime, '{y}-{m}-{d}') }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="项目名称" align="center" prop="projectId" :show-overflow-tooltip="true" />
                        <el-table-column label="责任人" align="center" prop="dutyPerson" />
                        <el-table-column label="发证机构" align="center" prop="certificateInstitution"
                            :show-overflow-tooltip="true" />
                        <el-table-column label="服务机构" align="center" prop="serviceInstitu"
                            :show-overflow-tooltip="true" />
                        <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
                        <el-table-column label="创建人" align="center" prop="createId" :show-overflow-tooltip="true"
                            width="100" />
                        <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.honer_status" :value="scope.row.status" />
                            </template>
                        </el-table-column>
                        <el-table-column label="附件" align="center" prop="uploadFile">
                            <template slot-scope="scope">
                                <el-button @click.stop="handlePictureCardPreviewResume(scope.row.uploadFile)"
                                    size="small" type="text">附件</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
                            <template slot-scope="scope">
                                <el-button size="mini" type="text" icon="el-icon-edit"
                                    @click="handleUpdateLvli(scope.row, scope.$index)" title="编辑"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <pagination v-show="totalResume > 0" :total="totalResume" :page.sync="queryResume.pageNum"
                        :limit.sync="queryResume.pageSize" @pagination="getResumeList" />
                </el-col>
            </el-row>
        </el-dialog>
        <el-dialog :title="title" :visible.sync="openUser" width="1200px" append-to-body>
            <div style="height:85vh">
                <el-scrollbar>

                    <div class="content-box">
                        <BusinessInfo :markAs="1" @change="close" @ok="selectEnterprise" :enterprise="1">

                        </BusinessInfo>
                    </div>
                </el-scrollbar>
            </div>
        </el-dialog>

        <!-- 添加或修改荣誉资质履历对话框 -->
        <el-dialog title="新增/编辑" :visible.sync="openResume" width="700px" append-to-body @close="closeDig">
            <div v-if="resumeSign === 1">
                <el-descriptions title="">
                    <el-descriptions-item label="序号">
                        <el-tag size="medium">{{ index }}</el-tag>
                    </el-descriptions-item>
                </el-descriptions>
            </div>
            <el-form ref="form" :model="formResume" :rules="rulesResume" label-width="90px" :inline="true">
                <el-form-item label="关联方式" prop="concat">
                    <el-input v-model="formResume.concat" placeholder="请输入关联方式" maxlength="30" />
                </el-form-item>
                <el-form-item label="项目名称" prop="projectId">
                    <el-input v-model="formResume.projectId" placeholder="请输入项目名称" maxlength="30" />
                </el-form-item>
                <el-form-item label="责任人" prop="dutyPerson">
                    <el-input v-model="formResume.dutyPerson" placeholder="请输入责任人" maxlength="15" />
                </el-form-item>
                <el-form-item label="发证机构" prop="certificateInstitution">
                    <el-input v-model="formResume.certificateInstitution" placeholder="请输入发证机构" maxlength="20" />
                </el-form-item>
                <el-form-item label="服务机构" prop="serviceInstitu">
                    <el-input v-model="formResume.serviceInstitu" placeholder="请输入服务机构" maxlength="20" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="formResume.remark" placeholder="请输入备注" />
                </el-form-item>
                <el-form-item label="状态" prop="status">
                    <el-select v-model="formResume.status" placeholder="请选择状态" style="width: 178px">
                        <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间" prop="honorTime">
                    <el-date-picker clearable v-model="formResume.honorTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择时间" style="width: 178px" disabled="true">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="创建人" prop="createId">
                    <el-input v-model="formResume.createId" placeholder="请输入创建人" disabled="true" />
                </el-form-item>
                <el-form-item label="附件" prop="uploadFile">
                    <file-view v-if="show" :type="typeSelect" :businessId="formResume.uploadFile"
                        :businessCode="businessCode" @getFile="getFile"></file-view>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitFormResume">确 定</el-button>
                <el-button @click="cancelResume">关 闭</el-button>
            </div>
        </el-dialog>
        <!--   荣誉资质 附件展示对话框-->
        <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
            <UploadFile :upload-id="uploadId" :business-code="uploadCode"></UploadFile>
        </el-dialog>
        <!--   履历 附件展示对话框-->
        <el-dialog title="查看附件" :visible.sync="resumeFileList" width="500px" append-to-body v-if="resumeFileList">
            <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
        </el-dialog>
        <el-dialog :visible.sync="dialogVisible" append-to-body>
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
import { listManagement, getManagement, delManagement, addManagement, updateManagement, treeHonor, reviceHonor } from "@/api/honor/management";
import { getToken } from '@/utils/auth'
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/enterprise/info";
import BusinessInfo from "../enterprise/info/index.vue";
import { listResume, getResume, delResume, addResume, updateResume } from "@/api/honor/resume";
import dia from "../enterprise/seas/dialog.vue";
import FileView from "@/components/FileView/index"
import MainType from "@/components/MainType/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listType } from "@/api/maintype/type";
import UploadFile from "../upload/index.vue";
export default {
    name: "honor",
    components: { UploadFile, dia, BusinessInfo, FileView, MainType, Treeselect },
    dicts: ['certificate_type', 'certificate_level', 'honer_status', 'honor_urlname'],
    props: {
        enterpriseId: {
            type: String,
            default: null
        },
        enterpriseName: {
            type: String,
            default: null
        },
        isShow: {
            type: String,
            default: ""
        },
        isOpen: {
            type: Boolean,
            default: false
        },
        orgId: {
            type: String,
            default: null
        }
    },

    data() {

        return {
            headers: {
                'Authorization': 'Bearer ' + getToken()
            },
            //主分类
            typeCode: 'honor',
            typeCodeResume: 'honor_resume',
            uploadCode: 'honor',
            showUpload: false,
            typeSelectHonor: 0,
            // 遮罩层
            loading: true,
            ImgDig: false,
            dialogImageUrl: null,
            // 选中数组
            ids: [],
            // 证书类型选项
            deptOptions: undefined,
            defaultProps: {
                children: "children",
                label: "label"
            },
            //附件预览
            dialogVisible: false,
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 荣誉资质履历表格数据
            resumeList: [],
            // 荣誉资质信息表格数据
            managementList: [],
            // 弹出层标题
            title: "",
            //主分类
            options: null,
            //主分类:履历
            optionsResume: null,
            // 是否显示弹出层
            open: false,
            show: false,
            openUser: false,
            //父传子的履历附件标志位
            typeSelect: 0,
            //当前履历总数
            totalResume: 0,
            // 查询参数
            queryParams: {
                name: null,
                type: '',
                customerId: null,
                level: null,
                status: null,
                pageNum: 1,
                pageSize: 5,
                classificationId: null,
                organizationId: null,
                enterpriseName: null
            },
            //查询条件，履历
            queryResume: {
                pageNum: 1,
                pageSize: 15,
                honorId: null,
                classificationId: null
            },
            //履历id
            resumeId: null,

            //传递给子类的表单数据
            formResume: {},
            //新增履历弹框
            openResume: false,
            // 表单参数
            form: {},
            //附件对话框
            openFileList: false,
            resumeFileList: false,
            uploadId: null,
            //控制修改和新增
            addSign: 0,
            //履历传递序号
            index: null,
            //履历对话框
            resumeOpen: false,
            //新增还是删除：履历
            resumeSign: 0,
            businessCode: 'resume',
            // 表单校验
            rules: {
                entryTime: [
                    { required: true, message: '请选择发证时间', trigger: 'change' }
                ],
                abutmentTime: [
                    { required: true, message: '请选择预警时间', trigger: 'change' }
                ],
                name: [
                    { required: true, message: '请输入证书名称', trigger: 'blur' }
                ],
                // type: [
                //   { required: true, message: '请选择证书类别', trigger: 'change' }
                // ],
                // level: [
                //   { required: true, message: '请选择证书级别', trigger: 'change' }
                // ],
                // certificateInstitution: [
                //   { required: true, message: '请输入发证机构', trigger: 'blur' }
                // ],
                issuanceTime: [
                    { required: true, message: '请选择证书到期时间', trigger: 'change' }
                ],
                // effectiveTime: [
                //   { required: true, message: '请输入有效时间', trigger: 'blur' }
                // ]
                // 如果有其他字段需要添加校验规则，请继续在此处添加
            },
            rulesResume: {
                concat: [
                    { required: true, message: '请输入关联方式', trigger: 'blur' }
                ],
                projectId: [
                    { required: true, message: '请输入项目名称', trigger: 'blur' }
                ],
                certificateInstitution: [
                    { required: true, message: '请输入发证机构', trigger: 'blur' }
                ],
                serviceInstitu: [
                    { required: true, message: '请输入服务机构', trigger: 'blur' }
                ]
            },

            enterpriseList: [],
        };
    },
    created() {
        this.getDeptTree();
        this.getList();
        this.getEnterInfoList();
        this.listTypeResume();
    },
    //监听子组件弹框的boolean值,用于关闭弹窗后，数据重新加载
    watch: {
        openResume: function (newValue, oldValue) {
            // 在someValue发生变化时执行的操作
            console.log('someValue changed:', newValue);
            // 调用您想要执行的方法
            this.getResumeList();
        },
        // enterpriseId:function (newValue,oldVal){
        //
        //   this.getList();
        // }
        orgId: function (newValue, oldValue) {
            console.log("新值:" + newValue)
            this.queryParams.organizationId = newValue
            this.getList();
        },
    },


    methods: {
        //获取树节点数据
        listType() {
            listType({ typeCode: 'honor' }).then(res => {
                this.options = res.data;
            })
        },
        changeColor({ row }) {
            const currentDate = new Date();
            const selectedDate = new Date(row.abutmentTime);
            // 计算毫秒级的时间差
            const timeDifference = selectedDate - currentDate;
            // 将毫秒转换为天数
            const daysDifference = timeDifference / (1000 * 60 * 60 * 24);
            // 如果时间差小于3个月（约90天），返回红色，否则返回空字符串
            if (daysDifference < 90) {
                return {
                    color: "orange",
                    height: '30px' // 这个return的就是样式 可以是color 也可以是backgroundColor
                }
            } else {
                return {
                    height: '30px' // 这个return的就是样式 可以是color 也可以是backgroundColor
                }
            }
        },
        //获取树节点数据
        listTypeResume() {
            listType({ typeCode: 'honor_resume' }).then(res => {
                this.optionsResume = res.data;
            })
        },
        /** 查询荣誉资质信息列表 */
        getList() {
            this.loading = true;
            listManagement(this.queryParams).then(response => {
                this.loading = false;
            });
        },
        // 筛选节点
        filterNode(value, data) {
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        },
        getFile(data) {
            console.log(JSON.stringify(data))
        },
        // 节点单击事件
        handleNodeClick(data) {
            this.queryParams.type = data.id;
            this.handleQuery();
        },
        //荣誉资质:树点击事件
        getNode(data) {
            console.log(data)
            if (data.parentId != '00000000-0000-0000-0000-000000000000') {
                this.queryParams.classificationId = data.id
            } else {
                this.queryParams.classificationId = null;
            }
            this.getList()
        },
        //履历:树点击事件
        getNodeResume(data) {
            console.log(data)
            if (data.parentId != '00000000-0000-0000-0000-000000000000') {
                this.queryResume.classificationId = data.id
            } else {
                this.queryResume.classificationId = null;
            }
            this.getResumeList();
        },
        getDeptTree() {
            treeHonor().then(response => {
                this.deptOptions = response.data;
            });
        },
        getWarningColor(abutmentTime) {
            const currentDate = new Date();
            const selectedDate = new Date(abutmentTime);
            // 计算毫秒级的时间差
            const timeDifference = selectedDate - currentDate;
            // 将毫秒转换为天数
            const daysDifference = timeDifference / (1000 * 60 * 60 * 24);
            // 如果时间差小于3个月（约90天），返回红色，否则返回空字符串
            return daysDifference < 90 ? "red" : "";
        },
        //履历对话框
        handleLvli(row) {
            this.reset();
            const id = row.id || this.ids
            this.queryResume.honorId = row.id;
            this.resumeId = row.id;
            this.getResumeList();
            this.resumeOpen = true;
        },
        handleLvRevice(row) {
            this.$confirm("是否接收该荣誉资质证书？", "提示", {
                confirmButtonText: "确认",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    reviceHonor(row.id).then(res => {
                        if (res.code === 200) {
                            this.$message.success("接收成功");
                            this.getList();
                        } else {
                            this.$message.error("接收失败");
                            this.getList();
                        }
                    })
                })
        },
        handleUpdateLvli(row, index) {
            this.resumeId = row.id;
            this.openResume = true;
            this.index = index + 1;
            this.resumeSign = 1;
            this.typeSelect = 1;
            this.listTypeResume();
            getResume(this.resumeId).then(res => {
                this.formResume = res.data;
                this.show = true;
            })
        },
        handleClick(url) {
            if (!url.startsWith('http://') && !url.startsWith('https://')) {
                // 如果没有协议，添加默认的http://协议
                url = 'http://' + url;
            } window.open(url, '_blank');
        },
        //新增履历
        handleAddResume() {
            this.resetResume();
            this.formResume.uploadFile = new Date().getTime()
            this.formResume.honorTime = new Date();
            this.formResume.createId = this.$store.state.user.name;
            this.formResume.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
            this.listTypeResume();
            this.openResume = true;
            this.resumeSign = 0;
            //弹出框选择，默认为0
            this.typeSelect = 0;
            this.show = true;

        },
        //保存
        submitFormResume() {
            console.log(JSON.stringify(this.formResume))
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.formResume.id != null) {
                        this.formResume.honorId = this.honorId;
                        console.log(this.formResume.uploadFile)
                        updateResume(this.formResume).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.getResumeList();
                            this.openResume = false;
                            this.open = false;
                            this.typeSelect = null;
                            this.resetResume();
                            this.show = false;

                        });
                    } else {
                        this.formResume.honorId = this.queryResume.honorId
                        this.formResume.createId = this.$store.state.user.name;
                        console.log(this.formResume)
                        addResume(this.formResume).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.getResumeList();
                            this.openResume = false;
                            this.open = false;
                            this.typeSelect = null;
                            this.resetResume();
                            this.show = false;

                        });
                    }
                }
            });
        },
        //取消履历
        cancelResume() {
            this.openResume = false;
            this.show = false;
            this.resetResume();
        },
        closeDig() {
            this.openResume = false;
            this.show = false;
            this.resetResume();
        },
        resetResume() {
            this.formResume = {
                id: null,
                honorId: null,
                concat: null,
                honorTime: null,
                projectId: null,
                dutyPerson: null,
                certificateInstitution: null,
                serviceInstitu: null,
                remark: null,
                uploadFile: null
            };
        },
        /** 查询荣誉资质履历列表 */
        getResumeList() {
            this.loading = true;
            console.log(this.queryResume)
            listResume(this.queryResume).then(response => {
                this.resumeList = response.rows;
                console.log(this.resumeList)
                this.totalResume = response.total;
                this.loading = false;
            });
        },
        handleExceed(files, fileList) {
            this.$message.warning("只允许上传一个文件");
        },
        beforeUpload(file) {
            let size10M = file.size / 1024 / 1024 < 20
            if (!size10M) {
                this.$message.warning('上传文件大小不能超过 20MB!');
                return false
            }
        },
        //企业信息查询
        getEnterInfoList() {
            listInfo().then(res => {
                this.enterpriseList = res.rows;

            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.showUpload = false;
            this.reset();
        },
        enterprise() {
            this.openUser = true;
            this.title = '选择';
        },
        close() {
            this.openUser = false
        },
        selectEnterprise(data) {
            this.form.customerId = data.enterpriseId
            this.form.enterpriseName = data.enterpriseName
            console.log(this.form)
            this.close()
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                type: null,
                name: null,
                certificateNo: null,
                serviceInstitu: null,
                issuanceTime: null,
                effectiveTime: null,
                abutmentTime: null,
                attachment: null,
                operateId: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                creationTime: null,
                enterpriseName: null,
                customerId: null,
                operateTime: null,
                list: [],
                fileList: [],
                createId: null,
                entryTime: null,
                uploadFile: null,
                fileUrl: null,
                luRu: null,
                receive: null,
                urlName: null,
            };
            this.resetForm("form");
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.showUpload = true
            this.typeSelectHonor = 0;
            this.form.uploadFile = new Date().getTime();
            this.open = true;
            this.addSign = 0;
            this.title = "新增";
            this.form.createId = this.$store.state.user.name;
            if (this.queryParams.classificationId === null) {
                this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
            } else {
                this.form.classificationId = this.queryParams.classificationId;
            }
            this.listType();
            //获取当前时间
            this.form.creationTime = new Date();
            console.log(this.$store.state.user.name)
            if (this.enterpriseId != null) {
                this.form.enterpriseName = this.enterpriseName
                this.form.customerId = this.enterpriseId
            }
        },
        //拿到服务器返回的数据
        handle_success(res) {
            this.form.list.push(res);
            console.log(this.form.list)
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams = {
                name: null,
                type: '',
                level: null,
                pageNum: 1,
                pageSize: 15,
            };
            this.handleQuery();
        },
        //履历重置
        resetReusume() {
            this.queryResume.classificationId = null
            this.getResumeList();
        },
        resetReusumeClose() {
            this.queryResume.classificationId = null
        },
        /** 修改按钮操作 */
        handleUpdate(row, index) {
            this.reset();
            const id = row.id || this.ids
            getManagement(id).then(response => {
                this.form = response.data;
                this.form.index = index + 1;
                this.form.effectiveTime = row.effectiveTime;
                this.showUpload = true;
                this.typeSelectHonor = 1;
                if (this.form.uploadFile === null) {
                    this.form.uploadFile = new Date().getTime();
                }
                this.form.list = [];
                console.log(this.form)
                this.listType();
                this.open = true;
                this.title = "修改";
                this.addSign = 1;
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateManagement(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.showUpload = false;
                            this.getList();
                            this.$emit('change');
                        });
                    } else {
                        if (this.enterpriseId !== null) {
                            this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
                        }
                        addManagement(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.form.fileList = null;
                            this.showUpload = false;
                            this.getList();
                            this.$emit('change');
                        });
                    }
                }
            });
        },
        //序号展示
        indexMethod(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除荣誉资质信息名称为"' + row.name + '"的数据项？').then(function () {
                return delManagement(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        handlePictureCardPreview(url) {
            this.dialogVisible = true;
            this.dialogImageUrl = url;
            // this.uploadId = id;
            // this.openFileList = true;
        },
        handlePictureCardPreviewResume(id) {
            this.uploadId = id;
            this.resumeFileList = true;
        }
    }
};
</script>
<style scoped>
.warning-color {
    color: red;
    /* 设置预警条件下的所需样式 */
}

.warning-row {
    background-color: orange;
}

.thumbnail-image {
    width: 90px;
    /* 根据需求调整宽度 */
    height: 50px;
    object-fit: cover;
    border: 1px solid #ccc;
    /* 可选，添加边框样式 */
}
</style>
